<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>漏斗分析详情</title>
    <%@include file="../include/commonFile.jsp" %>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <style type="text/css">
        .list_item {
            padding-bottom: 35px;
            border-bottom: 1px dashed #cccccc;
            margin-bottom: 45px
        }

        .list_item .item_left {
            width: 15%;
            float: left;
            height: 45px;
        }

        .list_item .item_right {
            position: relative;
            width: 85%;
            float: left
        }

        .list_item .item_right .color_block {
            height: 45px;
            position: absolute;
            text-align: center;
            line-height: 45px;
        }

        .list_item .item_bottom {
            position: relative;
            margin-left: 15%
        }

        .list_item .item_bottom .squaren_border {
            margin-top: 15px;
            width: 100px;
            background-color: #F1F1FA;
            height: 40px;
            margin-bottom: -20px;
            text-align: center;
            line-height: 40px;
            position: absolute;
        }

        .list_item .item_bottom .triangle_border_down {
            width: 0;
            height: 0;
            border-width: 10px 50px 0;
            border-style: solid;
            border-color: #F1F1FA transparent transparent; /*灰 透明 透明 */
            position: absolute;
            top: 55px;
        }

        .color_gray {
            background-color: #F8F8F8;
            z-index: 1;
        }

        .color_green {
            background-color: #B8E986;
            z-index: 2;
        }
    </style>
</head>
<body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <form class="layui-form" action="${ctx}/analysis/funnel/detail.do?funnelId=${statisticsFunnel.id}" id="myForm" method="post">
                <div class="f-search-bar">
                    <div class="search-container">
                        <ul class="search-form-content">
                            <li class="form-item-inline">
                                <label class="search-form-lable">合作机构</label>
                                <div class="layui-input-inline">
                                    <select name="partnerId" lay-search>
                                        <option value="">全部合作商</option>
                                        <c:forEach var="partner" items="${partnerList}">
                                            <option value="${partner.id}" <c:if test="${partner.id == partnerId}">selected="selected"</c:if>>${partner.realname}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <div class="sub-btns">
                                    <a class="layui-btn layui-btn-danger"
                                       href="javascript:submitFunctionNew('#myForm')">查询</a>
                                    <a class="layui-btn layui-btn-normal"
                                       href="javascript:resetFunction('#myForm')">重置</a>
                                </div>
                            </li>
                        </ul>
                        <ul class="search-form-content">
                            <li class="form-item"><label class="search-form-lable">记录时间</label>
                                <div class="check-btn-inner" id="timeType">
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),2,'#myForm')" ${input.timeType == 2 ? 'class="active"' : ''}>昨天</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),3,'#myForm')" ${input.timeType == 3 ? 'class="active"' : ''}>最近7天</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),4,'#myForm')" ${input.timeType == 4 ? 'class="active"' : ''}>最近30天</a>
                                    <input type="hidden" name="timeType" value="${input.timeType}"/>
                                </div>
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createStart"
                                               value="${input.createStart}" placeholder="开始日">
                                    </div>
                                    -
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createEnd"
                                               value="${input.createEnd}" placeholder="截止日">
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </form>
            <div class="list-content">
                <div class="cl">
                    <table class="layui-table">
                        <colgroup>
                            <col>
                            <col>
                            <col>
                            <col>
                        </colgroup>
                        <thead>
                        <tr>
                            <th>步骤</th>
                            <th>用户数</th>
                            <th>发生次数</th>
                            <th>上一步转化率</th>
                            <th>总转化率</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach var="funnel" items="${funnelOutputs}" varStatus="st">
                            <tr>
                                <td>${funnel.name}</td>
                                <td>${funnel.uv}</td>
                                <td>${funnel.pv}</td>
                                <td>
                                    <c:if test="${empty funnel.lastConvert}">-</c:if>
                                    <c:if test="${not empty funnel.lastConvert}">
                                        <fmt:formatNumber value="${funnel.lastConvert}" pattern="#.##"/>%
                                    </c:if>
                                </td>
                                <td>
                                    <c:if test="${empty funnel.totalConvert}">-</c:if>
                                    <c:if test="${not empty funnel.totalConvert}">
                                        <fmt:formatNumber value="${funnel.totalConvert}" pattern="#.##"/>%
                                    </c:if>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="content mt15" id="charts" style="width: 80%; margin-top: 30px"></div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>
</div>
<script type="text/html" id="item_template">
    <div class="list_item item_{{ d.index }}">
        <div class="item_left">{{ d.name }}</div>
        <div class="item_right">
            <div class="color_block color_gray" style="width: {{ d.lastWidth }}px; max-width: {{ d.maxWidth }}px;"></div>
            <div class="color_block color_green" style="width: {{ d.currentWidth }}px; max-width: {{ d.maxWidth }}px;">{{ d.currentPv }}</div>
        </div>
        <div class="cl"></div>
        <div class="item_bottom">
            <div class="squaren_border">{{ d.lastConvert }}%</div>
            <!-- 向下的三角形 -->
            <div class="triangle_border_down">
                <span></span>
            </div>
        </div>
    </div>
</script>
<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>
<script type="text/javascript">
    txz.initHeader({
        nav: [{
            name: '漏斗分析',
            curr: true
        }, {
            name: '${statisticsFunnel.name}'
        }],
        info: '',
        btns: [{
            name: '返回',
            href: '${ctx}/analysis/funnel/list.do',
            icon: 'back'
        }]
    });
    $(function () {
        //加载日历
        layui.use(['laydate', 'laytpl'], function () {
            var laydate = layui.laydate, laytpl = layui.laytpl;

            // 查询开始日期
            var start = {
                elem: 'input[name=s_start]'
            };

            var end = {
                elem: 'input[name=s_end]'
            };
            laydate.render(start);
            laydate.render(end);

            // 查询发布日期
            var start = {
                elem: 'input[name=createStart]',
                done: function(value, date, endDate){
                    $(".check-btn-inner *").removeClass("active");
                    $("[name=timeType]").val("");
                }
            };

            var end = {
                elem: 'input[name=createEnd]',
                done: function(value, date, endDate){
                    $(".check-btn-inner *").removeClass("active");
                    $("[name=timeType]").val("");
                }
            };
            laydate.render(start);
            laydate.render(end);

            function paint() {
                var getTpl = $("#item_template").html();
                var flowDatas = '${flowDatas}';
                var datas = JSON.parse(flowDatas);
                var maxWidth = 0;
                $("#charts").html("");
                for (var i = 0; i < datas.length; i++) {
                    var $lastEle = $("#charts").find(".list_item:last-child");
                    var data = datas[i];
                    if ($lastEle.length > 0) {
                        var lastWidth = $lastEle.find(".color_green").width();
                        data['lastWidth'] = lastWidth;
                        data['currentWidth'] = (lastWidth * (data.lastConvert / 100)).toFixed(2);
                    } else {
                        var maxWidth = parseInt($("#charts").width() * 0.85);
                        if (data.lastConvert == 0) {
                            maxWidth = 0;
                        }
                        data['lastWidth'] = maxWidth;
                        data['currentWidth'] = maxWidth;
                        maxWidth = maxWidth;
                    }
                    data['maxWidth'] = maxWidth;
                    data['index'] = i;
                    laytpl(getTpl).render(data, function (html) {
                        $("#charts").append(html);
                    });
                }
            }

            paint();
        });
    });
</script>
</body>
</html>